﻿using LWH.ByteProtocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ByteProtocolCSharpDemo
{
    /// <summary>
    /// 对基本数据进行包装，一般用于储存实际数据
    /// </summary>
    class IndefiniteLengthProtocol : AbstractIndefiniteLengthProtocol
    {
        private Int32ValueProperty mStringLengthProperty;
        private StringValueProperty mStringProperty;

        /// <summary>
        /// 包装数据，并将数据按顺序添加到协议中
        /// </summary>
        /// <param name="data"></param>
        public IndefiniteLengthProtocol(byte[] data = null) : base(data)
        {
            mStringLengthProperty = new Int32ValueProperty(mBasicStringProperty);

            mBasicStringProperty = new IndefiniteLengthProperty(this, (property) =>
            {
                return mStringLengthProperty.getValue();
            });
            mStringProperty = new StringValueProperty(mBasicStringProperty);


            addProperty(mHeaderProperty);
            addProperty(mStringLengthProperty);
            addProperty(mStringProperty);
        }

        #region Getter&Setter
        public Int32ValueProperty StringLengthProperty
        {
            get
            {
                return mStringLengthProperty;
            }
        }

        public StringValueProperty StringProperty
        {
            get
            {
                return mStringProperty;
            }

        }
        #endregion
    }
}
